package cn.com.dhc.danlu.widget.textview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;

import cn.com.dhc.danlu.R;

/**
 * @author: 李一方
 * @time: 2016-09-18 23:59
 * @mail: liyifang@danlu.com
 * @desc: 自定义字体的TextView
 */
public class CustomFontTextView extends TextView {

    public CustomFontTextView (Context context) {
        this (context, null);
    }

    public CustomFontTextView (Context context, AttributeSet attrs) {
        this (context, attrs, 0);
    }

    public CustomFontTextView (Context context, AttributeSet attrs, int defStyleAttr) {
        super (context, attrs, defStyleAttr);
        init (context, attrs);
    }

    private void init (Context context, AttributeSet attrs) {
        TypedArray ta = context.obtainStyledAttributes (attrs, R.styleable.CustomFontTextView);
        String fontFilePath = ta.getString (R.styleable.CustomFontTextView_fontFilePath);
        ta.recycle ();
        if (!TextUtils.isEmpty (fontFilePath)) {
            Typeface typeface = Typeface.createFromAsset (context.getAssets (), fontFilePath);
            setTypeface (typeface);
        }
    }
}
